package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Alarm;
import com.ruoyi.system.service.IAlarmService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警信息Controller
 * 
 * @author zbb
 * @date 2023-02-13
 */
@Controller
@RequestMapping("/alarm/alarm")
public class AlarmController extends BaseController
{
    private String prefix = "alarm/alarm";

    @Autowired
    private IAlarmService alarmService;

    @RequiresPermissions("alarm:alarm:view")
    @GetMapping()
    public String alarm()
    {
        return prefix + "/alarm";
    }

    /**
     * 查询报警信息列表
     */
    @RequiresPermissions("alarm:alarm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Alarm alarm)
    {
        startPage();
        List<Alarm> list = alarmService.selectAlarmList(alarm);
        return getDataTable(list);
    }

    /**
     * 导出报警信息列表
     */
    @RequiresPermissions("alarm:alarm:export")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Alarm alarm)
    {
        List<Alarm> list = alarmService.selectAlarmList(alarm);
        ExcelUtil<Alarm> util = new ExcelUtil<Alarm>(Alarm.class);
        return util.exportExcel(list, "报警信息数据");
    }

    /**
     * 新增报警信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警信息
     */
    @RequiresPermissions("alarm:alarm:add")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Alarm alarm)
    {
        return toAjax(alarmService.insertAlarm(alarm));
    }

    /**
     * 修改报警信息
     */
    @RequiresPermissions("alarm:alarm:edit")
    @GetMapping("/edit/{alarmId}")
    public String edit(@PathVariable("alarmId") Long alarmId, ModelMap mmap)
    {
        Alarm alarm = alarmService.selectAlarmByAlarmId(alarmId);
        mmap.put("alarm", alarm);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警信息
     */
    @RequiresPermissions("alarm:alarm:edit")
    @Log(title = "报警信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Alarm alarm)
    {
        return toAjax(alarmService.updateAlarm(alarm));
    }

    /**
     * 删除报警信息
     */
    @RequiresPermissions("alarm:alarm:remove")
    @Log(title = "报警信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(alarmService.deleteAlarmByAlarmIds(ids));
    }
}
